﻿using System;
using System.Reflection;

namespace Devonline.Core
{
    /// <summary>
    /// excel 导入导出通用标签
    /// excel Name, Size, FieldName, Format 等大多数参数可由扩展方法 GetExcelAttribute 计算得到默认值, 因此可以不做设置, 除非需要改变默认设置
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field)]
    public sealed class ExcelAttribute : Attribute
    {
        /// <summary>
        /// excel column Index
        /// </summary>
        public int Index { get; set; }
        /// <summary>
        /// excel column name
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// excel column size
        /// </summary>
        public float Size { get; set; }

        /// <summary>
        /// excel field is required
        /// </summary>
        public bool Required { get; set; }
        /// <summary>
        /// excel field value max input length
        /// </summary>
        public int MaxLength { get; set; }
        /// <summary>
        /// excel cell value format
        /// </summary>
        public string Format { get; set; }
        /// <summary>
        /// excel field info
        /// </summary>
        public MemberInfo Field { get; set; }
        /// <summary>
        /// excel field type
        /// </summary>
        public Type FieldType { get; set; }
        /// <summary>
        /// 处理 excel 单元格的委托方法
        /// 三个参数依次为: 当前值, 当前对象, 返回值
        /// </summary>
        public Func<object, object, object> GetValue { get; set; }
    }
}
